package com.example.smartcity.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.example.smartcity.R;
import com.example.smartcity.utils.JavaScriptinterface;


import java.io.IOException;

public class WebViewActivity extends AppCompatActivity {
    WebView webView;
    JavaScriptinterface javaScriptinterface;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_view2);
        initData();
    }

    private void initData(){
        webView = (WebView) findViewById(R.id.movie_webview);
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webView.clearCache(true);
        javaScriptinterface = new JavaScriptinterface(this, WebViewActivity.this);
        webView.addJavascriptInterface(javaScriptinterface,"plus");

        webView.loadUrl(url);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

}
